<?php
class LogModel extends Db {
	protected $_log = 'w_log';
	
	/**
	 * 增加日志记录
	 * @param unknown_type $params
	 */
	public function addLog($params) {
		$this->add ( $this->_log, $params );
	}
	
	/**
	 * 统计最近三十天的登录人数
	 * Enter description here ...
	 */
	public function tjLogin($days, $format = "%Y%m%d") {
		$sql = "select count(id) num,DATE_FORMAT(action_time,'$format') m from $this->_log GROUP by m order by m desc limit $days";
		return $this->fetchAll ( $sql );
	}
	
	/**
	 * 获取日志列表
	 * Enter description here ...
	 * @param unknown_type $start
	 * @param unknown_type $num
	 */
	public function getLogPage($start, $num) {
		return $this->getPage ( $start, $num, $this->_log,null,null,'id desc' );
	}
	
	public function countLogNum() {
		$sql = "SELECT id  FROM $this->_log";
		return $this->rowCount ( $sql );
	}
	
	/**
	 * 获取指定记录
	 * Enter description here ...
	 * @param unknown_type $where
	 */
	public function getLogByWhere($where, $limit) {
		return $this->getAll ( $this->_log, $where, NULL, "id DESC", $limit );
	}
	/**
	 * 返回log
	 * @return LogModel
	 */
	public static function instance() {
		return parent::_instance ( __CLASS__ );
	}
}